package com.itxx.keyCase;

import java.io.*;
import java.util.Arrays;

/*
在当前模块新建一个文件number.txt,文件中有以下内容:
3,5,4,7,12,9,10,1
要求将数据读取之后重新排序后存储到number.txt中.

*/
public class Test1_1 {
    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new FileWriter(new File("day12\\number.txt")));
        bw.write("3,5,4,7,12,9,10,1");
        bw.flush();
        bw.newLine();

        BufferedReader br = new BufferedReader(new FileReader(new File("day12\\number.txt")));
        String s = br.readLine();
        String[] split = s.split(",");
        int[] arr = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            arr[i] = Integer.parseInt(split[i]);
        }
        Arrays.sort(arr);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            if (i != arr.length - 1) {
                sb.append(arr[i] + ",");

            } else {
                sb.append(arr[i]);
            }
        }
        bw.write(sb.toString());
        bw.flush();

        //释放资源
        bw.close();
        br.close();

    }
}
